package com.hddz.acquisition.fragment.stock;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.hddz.acquisition.R;
import com.hddz.acquisition.activity.stock.InvDetailActivity;
import com.hddz.acquisition.fragment.BaseFragment;
import com.hddz.acquisition.model.StockResponseItem;
import com.hddz.acquisition.view.Free1SumAdapter;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

@ContentView(R.layout.view_stock_grounding_color_list)
public class FragmentFree1SumList extends BaseFragment {

	@ViewInject(R.id.list)
	private ListView list;
	Free1SumAdapter adapter = null;

	public static FragmentFree1SumList newInstance() {
		FragmentFree1SumList fragment = new FragmentFree1SumList();
		return fragment;
	}

	@Override
	public void appandChild(View view) {
		Bundle bundle = getArguments();
		String cmd = bundle.getString("COMMAND", "9001");
		adapter = new Free1SumAdapter(getActivity());
		list.setAdapter(adapter);
		if (!cmd.equals("9003")) {
			list.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(getActivity(), InvDetailActivity.class);
					intent.putExtra("TARGETWAREHOUSE", ((StockResponseItem) adapter.getItem(position)).cWarehouse);
					intent.putExtra("INVCODE", ((StockResponseItem) adapter.getItem(position)).cInvCode);
					intent.putExtra("FREE1", ((StockResponseItem) adapter.getItem(position)).cFree1);
					startActivity(intent);
				}
			});
		}
	}


	public void updateList(List<StockResponseItem> items) {
		adapter.updateList(items);
	}
}
